<?php
/**
 * User: zhangligang
 * Email: tzhang2450@163.com
 * Date: 2018/11/25
 * Time: 00:09
 */

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller as BaseController;

class Controller extends BaseController
{

    protected function sendJson(array $data, $status = 200, $message = 'OK')
    {
        echo json_encode([
            'body' => count($data) ? ['data' => $data] : new \stdClass(),
            'status' => $status,
            'message' => $message
        ]);exit;
    }

    protected function sendGet($callback)
    {
        try {
            $callback();
        } catch(\Exception $e) {
            var_dump($e);exit;
        }
    }

    protected function sendPost($callback)
    {
        try {
            $callback();
        } catch(\Exception $e) {
            var_dump($e->getMessage());exit;
        }
    }
}